package mysql

import (
	"data-transfer/plugins"
	"github.com/go-mysql-org/go-mysql/canal"
	"xorm.io/xorm"
)

// db 代表 mysql 数据库的逻辑连接
type db struct {
	dbKind plugins.DbKind
	dbName string

	db    *xorm.Engine
	canal *canal.Canal
}

// newDB 创建数据库实例，代表底层数据库的逻辑连接
func newDB(dbKind plugins.DbKind, dbName string, xdb *xorm.Engine, canal *canal.Canal) *db {
	mdb := &db{
		dbKind: dbKind,
		dbName: dbName,
		db:     xdb,
		canal:  canal,
	}
	return mdb
}

// Close closes the connection to the mysql db
func (mdb *db) Close() error {
	return mdb.db.Close()
}

// PluginName returns the name of the mysql plugin
func (mdb *db) PluginName() string {
	return PluginName
}
